//
//  DocumentListViewController.m
//  yonghu
//
//  Created by 浪尖渝力 on 2018/1/18.
//  Copyright © 2018年 com.DJS. All rights reserved.
//

#import "DocumentListViewController.h"
#import "DocumentListView.h"
@interface DocumentListViewController ()
@property(nonatomic,strong)DocumentListView *aView;
@property(nonatomic,strong)kongBaiye *kongBai;

@end

@implementation DocumentListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"代写文书";
    _aView=[DocumentListView new];
    [self.view addSubview:_aView];
    [_aView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    _aView.page1=1;
    _aView.tableArr=[NSMutableArray arrayWithCapacity:0];
    [_aView creatView];
    _aView.viewController=self;
    
    _aView.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [_aView.tableArr removeAllObjects];
        _aView.page1=1;
        [self loadData];
    }];
     [self loadData];
}
-(void)loadData{
    NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
    NSString *token=[userDic objectForKey:@"token"];
    NSNumber *waiter_id1=[userDic objectForKey:@"user_id"];
    NSString *user_id=[NSString stringWithFormat:@"%@",waiter_id1];
    NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:user_id,@"user_id",@"0",@"document_type",[NSString stringWithFormat:@"%d",_aView.page1],@"page",@"5",@"pagesize",token,@"token",@"0",@"user_role", nil];
    [ZQTools AFNPostDataUrl:@"user/Document/document_list" Dict:dic andTableView:nil andViewController:self andSuccessBlock:^(id responseObject) {
        
        [_aView.tableView.mj_footer endRefreshing];
        [_aView.tableView.mj_header endRefreshing];
        
        NSArray *typeArr=responseObject;
        [_aView.tableArr addObjectsFromArray:typeArr];
        [_aView.tableView reloadData];
        if (typeArr.count!=0) {
            _aView.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
                _aView.page1+=1;
                [self loadData];
            }];
        }
        else{
            _aView.tableView.mj_footer.hidden=YES;
        }
        [_kongBai shanChu];
        if (_aView.tableArr.count==0) {
            _kongBai=[kongBaiye new];
            [self.view addSubview:_kongBai];
            [_kongBai mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.bottom.mas_equalTo(0);
                make.top.mas_equalTo(NAV_HEIGHT);
            }];
            [_kongBai creatView];
            _kongBai.customSelectedBlock  = ^{
                [self loadData];
            };
        }
        
    } anderrorBlock:nil];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
